package com.itsu.spbspider.util;

import com.itsu.spbspider.entity.Job;
import lombok.extern.slf4j.Slf4j;

/**
 * @author suben
 * @create time 2020/2/6 19:10
 */
@Slf4j
public class ProjectUtil {

    public static Integer caculateSeconds(Job job) {
        String unit = job.getUnit();
        Integer seconds = job.getTimeInterval();
        switch (unit) {
            case "second":
                seconds = job.getTimeInterval();
                break;
            case "minute":
                seconds = job.getTimeInterval() * 60;
                break;
            case "hour":
                seconds = job.getTimeInterval() * 60 * 60;
                break;
            case "day":
                seconds = job.getTimeInterval() * 60 * 60 * 24;
                break;
            case "month":
                seconds = job.getTimeInterval() * 60 * 60 * 24 * 30;
                break;
            default:
                log.info("get no match of unit , will use second");
        }
        return seconds;
    }
}
